import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToMany } from 'typeorm';
import { Tag } from '../../tags/entities/tag.entity';
import { Text } from '../../texts/entities/text.entity';
import { GalleryImage } from '../../gallery/entities/gallery-image.entity';

@Entity('users')
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 50, unique: true, comment: '用户名' })
  username: string;

  @Column({ type: 'varchar', length: 20, unique: true, comment: '手机号' })
  phone: string;

  @Column({ type: 'varchar', length: 255, comment: '密码' })
  password: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '头像' })
  avatar: string;

  @Column({ type: 'tinyint', default: 1, comment: '状态：1-正常，0-禁用' })
  status: number;

  @CreateDateColumn({ 
    name: 'created_at',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间'
  })
  createdAt: Date;

  @UpdateDateColumn({ 
    name: 'updated_at',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
    comment: '更新时间'
  })
  updatedAt: Date;

  @OneToMany(() => Tag, tag => tag.user)
  tags: Tag[];

  @OneToMany(() => Text, text => text.user)
  texts: Text[];

  @OneToMany(() => GalleryImage, image => image.user)
  galleryImages: GalleryImage[];
}
